#!/usr/bin/env python
#-*- coding:utf-8 -*-
# Create by yanghongqiang
# Create on 2021/3/25
import   requests;
from  _ZSGK import  zsgk_storage;
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0",
};
def get_universities(start,end):
    base_url_pattern ="https://api.eol.cn/gkcx/api/?access_token=&admissions=&central=&department=" \
                       "&dual_class=&f211=&f985=&is_doublehigh=&is_dual_class=&keyword=&nature=&page=%d" \
                       "&province_id=&request_type=1&school_type=&signsafe=&size=15&sort=view_total" \
                       "&top_school_id=[770,771,3186]&type=&uri=apidata/api/gk/school/lists";
    url_list = list(base_url_pattern % item for item in range(start,end+1));
    universtities=[];
    for url in  url_list:
        print("Page: %d, Visit url: %s" % (url_list.index(url) + start, url));
        r = requests.get(url,headers = headers);
        if r.status_code ==200:
            current_universities = r.json().get("data").get("item");
            print(current_universities);
            zsgk_storage.universities_mysql(universtities);
            universtities  += current_universities;
        else:
            print("Request error, return status code is: %d" % (r.status_code,));
            return  universtities;
if __name__ == '__main__':
    universities = get_universities(130,180);

